package com.lingshi.shopping_manager_api.interceptor;

import cn.dev33.satoken.stp.StpUtil;
import com.lingshi.shopping.enums.ErrorEnums;
import com.lingshi.shopping.exception.BusException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;


@Component
public class CheckLoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        String requestURI = httpServletRequest.getRequestURI();
        System.out.println("requestURI = " + requestURI);
        //判断是否登录
        if(!StpUtil.isLogin()){
            //抛出逻辑异常
            throw new BusException(ErrorEnums.NO_LOGIN_ERROR);
        }
        return true;
    }
}
